<?xml version="1.0" encoding="utf-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:com="http://java.sun.com/jsf/composite/componentes"
    xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/templates/layout.xhtml">
    <h:outputStylesheet library="css" name="amostras.css" />
    <h:outputScript library="js" name="amostras.js" />
    
    <ui:include src="cadastro.xhtml" />

    <h2><h:outputText value="#{appMessages['amostras.titulo']}" /></h2>

    <h:form id="formAmostras">
        <p:toolbar id="tbAmostras" rendered="#{restrictions.cadastro}">
            <p:toolbarGroup>
                <p:commandButton
                    value="#{appMessages['amostras.cadastrar']}"
                    action="#{amostrasBean.cadastrarAmostra()}"
                    oncomplete="modalCadastro.show();"
                    update=":modalCadastro" />
            </p:toolbarGroup>
        </p:toolbar>
        
        <p:messages id="msgsAmostras" />
        
        <p:confirmDialog
            header="#{appMessages['amostras.remover.titulo']}"
            message="#{appMessages['amostras.remover.mensagem']}"
            widgetVar="confirmacaoRemover">
            <p:commandButton
                value="#{messages['resposta.sim']}"
                action="#{amostrasBean.removerAmostra()}"
                update="msgsAmostras dtAmostras"
                oncomplete="confirmacaoRemover.hide();" />
            <p:commandButton value="#{messages['resposta.nao']}" onclick="confirmacaoRemover.hide();" />
        </p:confirmDialog>
    
        <p:dataTable
            id="dtAmostras"
            value="#{amostrasBean.amostras}"
            var="amostra"
            paginator="true"
            paginatorAlwaysVisible="false"
            rows="10">
            
            <!-- Data -->
            <p:column headerText="#{appMessages['amostras.data']}">
                <h:outputText value="#{amostra.data}">
                    <f:convertDateTime dateStyle="medium" />
                </h:outputText>
            </p:column>
            
            <!-- Ponto de coleta -->
            <p:column headerText="#{appMessages['amostras.pontoColeta']}">
                <h:outputText value="#{amostra.pontoColeta.nome}" />
            </p:column>
            
            <!-- Bacia hidrográfica -->
            <p:column headerText="#{appMessages['amostras.baciaHidrografica']}">
                <h:outputText value="#{amostra.pontoColeta.corpoHidrico.baciaHidrografica.nome}" />
            </p:column>
            
            <!-- Condição climática -->
            <p:column headerText="#{appMessages['amostras.condicaoClimatica']}">
                <h:outputText value="#{amostra.condicaoClimatica.nome}" />
            </p:column>
            
            <!-- IQA -->
            <p:column headerText="#{appMessages['amostras.iqa']}" style="text-align: center;">
                <h:outputText
                    value="#{amostra.IQA}"
                    styleClass="label-qualidade"
                    style="background-color: ##{amostra.qualidade.corHexa}; color: ##{amostra.qualidade.corHexaTexto}">
                    <f:convertNumber maxFractionDigits="2" minFractionDigits="2" />
                </h:outputText>
            </p:column>
            
            <p:column>
                <p:button
                    icon="ui-icon-print"
                    title="#{appMessages['amostras.relatorio.imprimir']}"
                    onclick="Amostras.abrirImpressao(#{amostra.idAmostra}); return false;" />
                <p:commandButton
                    icon="ui-icon-pencil"
                    title="#{appMessages['amostras.alterar']}"
                    action="#{amostrasBean.carregarAmostra()}"
                    oncomplete="modalCadastro.show();"
                    update=":formAmostra"
                    rendered="#{restrictions.cadastro}" />
                <p:commandButton
                    icon="ui-icon-close"
                    title="#{appMessages['amostras.remover']}"
                    action="#{amostrasBean.carregarAmostra()}"
                    oncomplete="confirmacaoRemover.show();"
                    rendered="#{restrictions.cadastro}" />
            </p:column>
        </p:dataTable>
    </h:form>
</ui:composition>
</html>